package edu.gatech.cs2340.group7.wheresmystuffapp.views;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import edu.gatech.cs2340.group7.wheresmystuffapp.R;
import edu.gatech.cs2340.group7.wheresmystuffapp.presenters.AdminRemoveAccountPresenter;

public class AdminRemoveAccountView extends Activity implements OnClickListener {
	private AdminRemoveAccountPresenter myPresenter;
	private Button bCancel;
	private Button bDelete;
	private EditText accountToDelete;
	private TextView tvDeleteResult;
	private String PACKAGE_NAME;
	
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_remove_account);
		
		linkSetup();
		myPresenter = new AdminRemoveAccountPresenter(this);
		PACKAGE_NAME = getApplicationContext().getPackageName();
	}



	@Override
	public void onClick(View v) {
		switch(v.getId()) {
		case R.id.b_admin_cancel_from_delete:
			String username = accountToDelete.getText().toString();
			myPresenter.deleteAccount(username);
			break;
		case R.id.b_admin_delete:
			Intent intent = new Intent(this, AdminMainMenuView.class);
			intent.setPackage(PACKAGE_NAME);
			startActivity(intent);
			break;
		}
		
	}
	
	/**
	 * Shows the admin the result of attempting to delete an account
	 * @param result Result of trying to delete an account
	 */
	public void setDeleteResult(String result) {
		tvDeleteResult.setTextColor(Color.RED);
		tvDeleteResult.setText(result);
	}
	
	/**
	 * Sets up the buttons and text views
	 */
	private void linkSetup() {
		bCancel = (Button) findViewById(R.id.b_admin_cancel_from_delete);
		bDelete = (Button) findViewById(R.id.b_admin_delete);
		accountToDelete = (EditText) findViewById(R.id.et_admin_email_delete);
		tvDeleteResult = (TextView) findViewById(R.id.tv_admin_delete_result);
		
		bCancel.setOnClickListener(this);
		bDelete.setOnClickListener(this);
	}
}
